#include <GA\operations\selection\TournamentSelector.hpp>
#include <algorithm>

unitraf::TournamentSelector::TournamentSelector(size_t tournamentSize)
{
	_tournamentSize = tournamentSize;
	_fit = 0;
}


unitraf::TournamentSelector::~TournamentSelector(void)
{
}

size_t unitraf::TournamentSelector::select( )
{
	size_t res = _fit->size( ); // more than maximum possible value

	for ( size_t i = 0; i < _tournamentSize; ++i )
	{
		res = std::min( res,  rand( ) % _fit->size( ) );
	}

	return res;
}


